<style>
    /*
    图片
     */
    #layui-upload-box li {
        width: 120px;
        height: 100px;
        float: left;
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        border: 1px solid #ddd;
    }

    #layui-upload-box-two li {
        width: 120px;
        height: 100px;
        float: left;
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        border: 1px solid #ddd;
    }

    #layui-upload-box li img {
        width: 100%;
    }

    #layui-upload-box-two li img {
        width: 100%;
    }

    #layui-upload-box li p {
        width: 100%;
        height: 22px;
        font-size: 12px;
        position: absolute;
        left: 0;
        bottom: 0;
        line-height: 22px;
        text-align: center;
        color: #fff;
        background-color: #333;
        opacity: 0.6;
    }

    #layui-upload-box-two li p {
        width: 100%;
        height: 22px;
        font-size: 12px;
        position: absolute;
        left: 0;
        bottom: 0;
        line-height: 22px;
        text-align: center;
        color: #fff;
        background-color: #333;
        opacity: 0.6;
    }



    #layui-upload-box li i {
        display: block;
        width: 20px;
        height: 20px;
        position: absolute;
        text-align: center;
        top: 2px;
        right: 2px;
        z-index: 999;
        cursor: pointer;
    }

    #layui-upload-box-two li i {
        display: block;
        width: 20px;
        height: 20px;
        position: absolute;
        text-align: center;
        top: 2px;
        right: 2px;
        z-index: 999;
        cursor: pointer;
    }

    /*
    组图
     */
    #layui-upload-box-multi li {
        width: 120px;
        height: 100px;
        float: left;
        position: relative;
        overflow: hidden;
        margin-right: 10px;
        border: 1px solid #ddd;
    }

    #layui-upload-box-multi li img {
        width: 100%;
    }

    #layui-upload-box-multi li p {
        width: 100%;
        height: 22px;
        font-size: 12px;
        position: absolute;
        left: 0;
        bottom: 0;
        line-height: 22px;
        text-align: center;
        color: #fff;
        background-color: #333;
        opacity: 0.6;
    }

    #layui-upload-box-multi li i {
        display: block;
        width: 20px;
        height: 20px;
        position: absolute;
        text-align: center;
        top: 2px;
        right: 2px;
        z-index: 999;
        cursor: pointer;
    }
</style>
<script>
    var multiImages = [];
    var multiFiles = [];
    var tong = $('#tong').val();   //桶名称
    var extensionType = $('#extensionType').val() ? $('#extensionType').val() : ''; //图片格式类型
    var multiImagesVal = $('.multiImage').val();
    var multiFilesVal = $('.multiFiles').val();

    if (multiImagesVal) {
        multiImages = multiImagesVal.split(',');
    }

    if (multiFilesVal) {
        multiFiles = multiFilesVal.split(',');
    }

    layui.use(['upload', 'laydate','form'], function () {
        var startDate = layui.laydate;
        var form      = layui.form;
        var element = layui.element;
        startDate.render({
            elem: '#start_time',
            type: 'datetime',
            done: function (value, date, endDate) {
                var startDate = new Date(value).getTime();
                var endTime = new Date($('#end_time').val()).getTime();
                if (endTime < startDate) {
                    layer.msg('结束时间不能小于开始时间');
                    $('#start_time').val($('#end_time').val());
                }
            }
        });
        var endData = layui.laydate;
        endData.render({
            elem: '#end_time',
            type: 'datetime',
            done: function (value, date, endDate) {
                var startDate = new Date($('#start_time').val()).getTime();
                var endTime = new Date(value).getTime();
                if (endTime < startDate) {
                    layer.msg('结束时间不能小于开始时间');
                    $('#end_time').val($('#start_time').val());
                    form.render();
                }
            }
        });
        var upload = layui.upload;
        upload.render({
            elem: '#uploadPic'
            , url: '{{ route("upload.image") }}'
            , multiple: false
            ,acceptMime: 'image/*'
            , data: {"_token": "{{ csrf_token() }}","type":tong,'extensionType':extensionType}
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                    $('#layui-upload-box').html('<li><img src="' + result + '" /><p>上传中</p></li>');
                });
            }
            , done: function (res) {
                console.log(res);
                if (res.code == 0) {
                    $('#thumb').val(res.url);
                    $('#layui-upload-box li p').text('上传成功');
                    return layer.msg(res.msg, {icon: 6});
                }
                return layer.msg(res.msg, {icon: 5});
            }
            , error: function(res){
                //请求异常回调
                console.log(res);
            }
        });
    });
    layui.use('layedit', function(){
        var layedit = layui.layedit;
        layedit.build('content'); //建立编辑器
    });
</script>
